import json
from cgi import test
from importlib_metadata import distribution, re
# from matplotlib.pyplot import step
import numpy as np
import math
import time
import sys
import os
import argparse
from colorama import Fore, Back, Style
from colorama import init

import threading
import multiprocessing

from c_acc import spawn2
from c_acc import spawn3

import nnpy

def spawn(num):
  while True:
    time.sleep(0.0001)

candidates = [1,2,3,4,5,6,7,8,9,10,11,12,13]
candidates_X_symmetry = {1,2,3,4,5}
candidates_L_symmetry = {6,7,8,9,10,11,12,13}

rules0 = {
    (1,0,2,0,'H'),
    (2,0,3,0,'H'),
    (3,0,4,0,'H'),
    (4,0,5,0,'H'),
    (5,0,4,0,'H'),
    (4,0,3,0,'H'),
    (3,0,2,0,'H'),
    (2,0,1,0,'H'),
    (1,0,1,0,'H'),
    (2,0,2,0,'H'),
    (3,0,3,0,'H'),
    (4,0,4,0,'H'),
    (5,0,5,0,'H')
}

rules = {
    (1,0,2,0,'H'),
    (2,0,3,0,'H'),
    (3,0,4,0,'H'),
    (4,0,5,0,'H'),
    (5,0,4,0,'H'),
    (4,0,3,0,'H'),
    (3,0,2,0,'H'),
    (2,0,1,0,'H'),
    (1,0,1,0,'H'),
    (2,0,2,0,'H'),
    (3,0,3,0,'H'),
    (4,0,4,0,'H'),
    (5,0,5,0,'H'),

    (6,0,1,0,'H'),
    (2,0,6,0,'H'),
    (1,0,6,0,'V'),
    (6,0,2,0,'V'),

    (7,0,2,0,'H'),
    (3,0,7,0,'H'),
    (2,0,7,0,'V'),
    (7,0,3,0,'V'),

    (8,0,3,0,'H'),
    (4,0,8,0,'H'),
    (3,0,8,0,'V'),
    (8,0,4,0,'V'),

    (9,0,4,0,'H'),
    (5,0,9,0,'H'),
    (4,0,9,0,'V'),
    (9,0,5,0,'V'),

    (2,0,10,0,'V'),
    (10,0,1,0,'V'),
    (1,0,10,0,'H'),
    (10,0,10,0,'H'),
    (10,0,1,0,'H'),

    (3,0,11,0,'V'),
    (11,0,2,0,'V'),
    (2,0,11,0,'H'),
    (11,0,11,0,'H'),
    (11,0,2,0,'H'),

    (4,0,12,0,'V'),
    (12,0,3,0,'V'),
    (3,0,12,0,'H'),
    (12,0,12,0,'H'),
    (12,0,3,0,'H'),

    (5,0,13,0,'V'),
    (13,0,4,0,'V'),
    (4,0,13,0,'H'),
    (13,0,13,0,'H'),
    (13,0,4,0,'H')
}

rules_dic = {}

def build_dic():
    for i in candidates:
        rules_dic[i] = set()

    for i in rules:
        k = i[0]
        rules_dic[k].add((i[1],i[2],i[3],i[4]))

    print(rules_dic)

# main function
def main():

    build_dic()

    start = time.time()
    
    res = 0
    for i in range(1000000):
        for j in rules0:
            # if (j[1],j[2],j[3],j[4]) in rules_dic[j[0]]:
            if j in rules:
                res += 1

    end = time.time()
    print(end - start)
    print(res)
    
# main entry
if __name__ == "__main__":
    main()
